'use strict';

const db = uniCloud.database();

exports.main = async (event, context) => {
	const { account, password } = event;
	
	// 查询管理员账号信息
	const admin = await db.collection('admin').where({
		account:account
	}).get()
	
	if (admin.data.length === 0){
		return { success: false, message: '账号或密码错误' }
	}
	
	const storePassword = admin.data[0].password
	
	if(password === storePassword){
		return { success: true, message:'登录成功', admin:admin.data[0].account }
	}else{
		return { success: false, message:'账号或密码错误' }
	}
	
	//返回数据给客户端
	return event
};
